﻿using MainService.ZNQD;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace MainService
{
    public static class ZNQDServer
    {
        public static string GetServerUrl(string url)
        {
            int index = url.IndexOf('/', 7);
            url = url.Substring(index);
            ServerAddress sa = MyServer.ServerConfig.ZNQD;
            return "http://" + sa.ServerIP + ":" + sa.ServerPort + url;
        }

        public static Solutions GetSolutionList()
        {
            ZNQD_JJFA.SolutionServiceService sss = new ZNQD_JJFA.SolutionServiceService();
            sss.Url = GetServerUrl(sss.Url);
            string xml = sss.querySolutionList();
            XmlSerializer xs = new XmlSerializer(typeof(Solutions));
            Solutions solutions = null;
            using (Stream sm = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                solutions = (Solutions)xs.Deserialize(sm);
            }
            return solutions;
        }

        public static Solution GetSolutionInfo(string solutionid, string version)
        {
            ZNQD_JJFA.SolutionServiceService sss = new ZNQD_JJFA.SolutionServiceService();
            sss.Url =GetServerUrl(sss.Url);
            string xml = sss.querySolution(solutionid, version);
            Console.Write(xml);
            return null;
        }
    }
}
